package com.ecfront.dao.impl;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.ecfront.dao.GoodsDAO;
import com.ecfront.pojo.Goods;


/**
 * @version 1.0
 * @author www.ecfrom.com
 */

public class GoodsDAOImpl extends HibernateDaoSupport implements GoodsDAO {

	protected void initDao() {}


	public void save(Goods transientInstance) {
		getHibernateTemplate().saveOrUpdate(transientInstance);
	}

	public void delete(Goods persistentInstance) {
		getHibernateTemplate().delete(persistentInstance);
	}


	public Goods findById(java.lang.Integer id) {
		Goods instance = (Goods) getHibernateTemplate().get(
					"com.ecfront.pojo.Goods", id);
		return instance;
	}


	public List findByProperty(String propertyName, Object value) {
		String queryString = "from Goods as model where model."
					+ propertyName + "= ?";
		return getHibernateTemplate().find(queryString, value);
	}

	public List findByGtitle(Object gtitle) {
		return findByProperty(GTITLE, gtitle);
	}

	public List findByGinfo(Object ginfo) {
		return findByProperty(GINFO, ginfo);
	}

	public List findByGrestCount(Object grestCount) {
		return findByProperty(GREST_COUNT, grestCount);
	}

	public List findByGprice(Object gprice) {
		return findByProperty(GPRICE, gprice);
	}

	public List findByGtradePrice(Object gtradePrice) {
		return findByProperty(GTRADE_PRICE, gtradePrice);
	}

	public List findByGisRecommend(Object gisRecommend) {
		return findByProperty(GIS_RECOMMEND, gisRecommend);
	}

	public List findByGisShow(Object gisShow) {
		return findByProperty(GIS_SHOW, gisShow);
	}

	public List findAll() {
		String queryString = "from Goods";
		return getHibernateTemplate().find(queryString);
	}

	public static GoodsDAO getFromApplicationContext(ApplicationContext ctx) {
		return (GoodsDAO) ctx.getBean("GoodsDAO");
	}
}